package com.workstudy.wstudy.controller;

import java.util.List;

import com.workstudy.wstudy.domain.WstApply;
import com.workstudy.wstudy.domain.WstTimeModel;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.workstudy.common.annotation.Log;
import com.workstudy.common.enums.BusinessType;
import com.workstudy.wstudy.domain.WstTime;
import com.workstudy.wstudy.service.IWstTimeService;
import com.workstudy.common.core.controller.BaseController;
import com.workstudy.common.core.domain.AjaxResult;
import com.workstudy.common.utils.poi.ExcelUtil;
import com.workstudy.common.core.page.TableDataInfo;

/**
 * 时间管理Controller
 * 
 * @author sun
 * @date 2021-05-05
 */
@Controller
@RequestMapping("/wstudy/time")
public class WstTimeController extends BaseController
{
    private String prefix = "wstudy/time";

    @Autowired
    private IWstTimeService wstTimeService;

    @RequiresPermissions("wstudy:time:view")
    @GetMapping()
    public String time()
    {
        return prefix + "/time";
    }

    @GetMapping("/selectTime")
    public String selectTime()
    {
        return prefix + "/select_time";
    }
    @GetMapping("/selectTime1")
    public String selectTime1()
    {
        return prefix + "/select_time1";
    }
    @GetMapping("/selectTime2")
    public String selectTime2()
    {
        return prefix + "/select_time2";
    }

    /**
     * 查询时间管理列表
     */
    @RequiresPermissions("wstudy:time:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(WstTime wstTime)
    {
        startPage();
        List<WstTime> list = wstTimeService.selectWstTimeList(wstTime);
        return getDataTable(list);
    }

    /**
     * 导出时间管理列表
     */
    @RequiresPermissions("wstudy:time:export")
    @Log(title = "时间管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WstTime wstTime)
    {
        List<WstTime> list = wstTimeService.selectWstTimeList(wstTime);
        ExcelUtil<WstTime> util = new ExcelUtil<WstTime>(WstTime.class);
        return util.exportExcel(list, "time");
    }


    /**
     * 新增时间管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存时间管理
     */
    @RequiresPermissions("wstudy:time:add")
    @Log(title = "时间管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(WstTime wstTime)
    {
        return toAjax(wstTimeService.insertWstTime(wstTime));
    }

    /**
     * 修改时间管理
     */
    @GetMapping("/edit/{timeId}")
    public String edit(@PathVariable("timeId") Long timeId, ModelMap mmap)
    {
        WstTime wstTime = wstTimeService.selectWstTimeById(timeId);
        mmap.put("wstTime", wstTime);
        return prefix + "/edit";
    }

    /**
     * 修改保存时间管理
     */
    @RequiresPermissions("wstudy:time:edit")
    @Log(title = "时间管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(WstTime wstTime)
    {
        return toAjax(wstTimeService.updateWstTime(wstTime));
    }

    /**
     * 删除时间管理
     */
    @RequiresPermissions("wstudy:time:remove")
    @Log(title = "时间管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(wstTimeService.deleteWstTimeByIds(ids));
    }

    //时间占用项
    @PostMapping("/apply")
    @ResponseBody
    public AjaxResult export(WstTimeModel list)
    {
        return toAjax(wstTimeService.insertWstTimeList(list));
    }

    //时间占用项
    @PostMapping("/listTimes")
    @ResponseBody
    public AjaxResult listTimes(WstTime time)
    {
        List<WstTime> list = wstTimeService.selectWstTimeList(time);
        return AjaxResult.success("获取数据成功",list);
    }

}
